package message;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import java.sql.*;
import java.util.ArrayList;
import javax.swing.JOptionPane;

public class testServlet1 extends HttpServlet {
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
		try{
			Connection con=null;
			Statement stmt=null;
			ResultSet rs=null;
			Class.forName("com.mysql.jdbc.Driver");
			String url="jdbc:mysql://localhost:3306/bedroomallocation?useUnicode=true&characterEncoding=gbk";
			con=DriverManager.getConnection(url,"root","root");
			stmt=con.createStatement();
			String sql="select * from 气质类型测试";
			rs=stmt.executeQuery(sql);
			ArrayList QList=new ArrayList();
			while(rs.next()){
				testBean1 tq=new testBean1();
				tq.setCount(rs.getInt("count"));
				tq.setQuestion(rs.getString("question"));
				HttpSession session=request.getSession();
				QList.add(tq);
				session.setAttribute("QList", QList);
			}
			response.sendRedirect("http://localhost:8888/BedroomAllocation/testQuestion.jsp");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
		doGet(request,response);
	}
}
